
    $(function () {
        var liNow; //当前的图片dom
        var tmpl = '<li class="weui-uploader__file" style="background-image:url(#url#)"></li>',
            $gallery = $("#gallery"),
            $galleryImg = $("#galleryImg");

        var $uploaderFiles = $("#uploaderFiles");
        var $uploaderInput = $("#uploaderInput");
        $uploaderInput.on("change", function (e) {
            var src, url = window.URL || window.webkitURL || window.mozURL,
                files = e.target.files;
            for (var i = 0, len = files.length; i < len && i < 1; ++i) {
                var file = files[i];

                if (url) {
                    src = url.createObjectURL(file);
                } else {
                    src = e.target.result;
                }
                $uploaderFiles.append($(tmpl.replace('#url#', src)));
                if ($uploaderFiles.children().length >= 1) {
                    $uploaderInput.parent().hide();
                }
            }
            $uploaderInput.val("");
        });
        $("#content").on("click", ".weui-uploader__file", showImg);
        $gallery.on("click", function () {
            $gallery.fadeOut(300);
        });

        function showImg() {
            liNow = $(this);
            $galleryImg.attr("style", this.getAttribute("style"));
            $gallery.fadeIn(300);
        }

        //删除图片
        $("#deletePic").click(function () {
            liNow.remove();
            if ($uploaderFiles.children().length < 1) {
                $uploaderInput.parent().show();
            }
        });
    });
